草庐IT

tcp 序列号

全部标签

c# - 类型为 T 的派生类的序列化

我有以下类需要序列化publicclassBoat{publicstringBrand{get;set;}publicstringModel{get;set;}}以及下面的派生类publicclassWindBoat:Boat{publicintMaxSpeed{get;set}}publicclassSpeedBoat:Boat{publicintMaxSpeed{get;set;}publicEngineEngine{get;set;}}当我尝试序列化Boat类时,它说我需要为所有可能的子类添加XmlInclude,但我无法添加SpeedBoat,因为我不知道我将提前拥有多少类型,

c# - 使用 WCF 将类序列化为由 xsd.exe 生成的 JSON

我想用WCF编写一个RESTfulWeb服务,它能够以JSON和XML进行回复。我有一个XML架构,我使用xsd.exe从中生成了我的类。只要我请求XML,一切都可以正常工作,但如果我想要JSON作为响应,它就会失败。System.ServiceModel.Dispatcher.MultiplexingDispatchMessageFormatter抛出System.Collections.Generic.KeyNotFoundException。问题是,到目前为止,我发现xsd.exe不会生成DataContract和DataMember属性。有什么解决方案可以解决我不需要使用Svc

c# - 在 C# 中将 FileInfo 对象序列化为 XML

我正在尝试序列化IEnumerable到XML中。我研究发现,因为FileInfo类没有无参构造函数,所以不能按原样序列化,应该使用包装类。为简单起见,我用来序列化的代码位于winforms按钮的单击事件中,如图所示。一旦它工作,我将重构它:privatevoidbutton1_Click(objectsender,System.EventArgse){IEnumerableallfiles=FileGetter.FileInfoAllFiles();FileListfilelist=newFileList();foreach(varfileinallfiles){filelist.A

c# - 在 .NET 2.0 中序列化私有(private)支持数据成员?

我正在编写一个小的xml配置文件,该文件将从特定位置保存和加载(因此不使用user.config)。我的应用程序是.NET2.0,无法移动到较新的版本(因此没有DataContractSerializer)我需要实现“保存密码”选项,以便在用户使用该应用程序。目前我是这样做的publicclassUserSettings{//Snipmanyotherproperties...publicboolSavePassword{get;set;}[XmlIgnore]publicstringPassword{get{stringretVal=string.Empty;if(Protected

java - 如何使用 JAXB 或 Jackson 有条件地序列化?外部 View 与内部 View

我正在构建一个RESTfulAPI,我有一个用例,我需要能够呈现我的数据的两个不同View。一个我们可以在内部使用,一个我们将在外部公开。此外,我的API需要同时支持XML和JSON。对于我的JSON响应,使用Jackson非常容易做到这一点。我可以使用JsonViews的功能有条件地在我的JSON响应中包含字段:http://wiki.fasterxml.com/JacksonJsonViews首先您需要创建一个简单的类来指定您的View:publicclassViews{publicstaticclassExternal{}publicstaticclassInternalexte

c# - 连同数据一起序列化 XmlDoc 注释

我有一个可序列化的类,我想用它的数据(当然)和它的XmlDoc注释来序列化它。有谁知道现有的图书馆可以完成这项工作,或者至少是其中的一部分?以Intellisense的方式阅读C#代码的XmlDoc是一个很好的起点。实例胜于理论,我想有如下(C#)代码publicclassApplicationOptions:ISerializable{///ThisparameterdescribestheXpropertypublicintWindowPositionX;///ThiscommentisthesameasintheXML-serializedformpublicintWindowP

xml - 对排序序列的操作不遵守排序顺序

我无法理解为什么XSLT(Saxon9.1和9.5)在使用包含已排序序列的变量时的工作方式。这是我的程序的输出,其中嵌入了我的三个问题:Thefollowingsequenceisunsorted...sequence$list=()Itis,asIexpected,indocumentorder.Thefollowingsequenceisexplicitlysorted...sequence$sorted-list=()Itis,asIexpected,sortedindescendingnumerical@eorder.Inthefollowingoutput,Iexpectfo

c# - 使用泛型类型和继承时在 REST API 上序列化 XML 时出错

当我将使用泛型类型的返回对象序列化为XML时,我的RESTAPI出现错误。使用JSON时不会重现此错误。这是一个演示我的问题的简化示例:usingSystem;usingSystem.Net;usingSystem.Net.Http;usingSystem.Runtime.Serialization;usingSystem.Threading.Tasks;usingSystem.Web.Http;namespaceAreas.API{publicabstractclassAnimalController:ApiControllerwhereTProperties:new(){prote

c# - 将对象序列化为 XML 时出现意外结果

我在创建以下架构时遇到问题...CNumber00645007803\12345678\00645007803\CNumber00645007804\12345678\00645007804\我创建了以下类来执行此操作publicclassDocumentProperties{publicDocumentProperties(){Document=newList();}publicListDocument{get;set;}}publicclassDocument{publicDocument(){Properties=newList();}publicListProperties{g

C# Xml Serializer 将列表反序列化为 0 而不是 null

我很困惑XmlSerializer在幕后工作。我有一个将XML反序列化为对象的类。我看到的是以下两个不属于正在反序列化的Xml的元素。[XmlRootAttribute("MyClass",Namespace="",IsNullable=false)]publicclassMyClass{privatestringcomments;publicstringComments{set{comments=value;}get{returncomments;}}privateSystem.Collections.Generic.Listtests=null;publicSystem.Colle